<?php


require_once 'AIS_DocComment.php';
require_once 'AIS_DocCommentTagParamWithRestrictions.php';
/**
 * Doc Comment for Function Comments
 */
class AIS_DocCommentFunction extends AIS_DocComment
{

	public function __construct($text)
	{
		parent::__construct($text);
	}
	
	private $tagFunctions = array(
	"@param" => "createParamTag");
	
	private function createParamTag($line)
	{
		$param = new AIS_DocCommentTagParamWithRestrictions($line, 3);
		$this->params[$param->getValue(1)] = $param;
		return $param;
	}
	
	private $params = array();
	private $paramIds = array();
	private $restrictions = array();
	
	/**
	 * 
	 *  
	 */
	protected function fillRestrictionsInVar()
	{
		$tags = $this->getTags('@param');
		if ($tags)
		{
		foreach ($tags as $tag)
		{
			$restrictions = isset($this->restrictions[$tag->getValue(1)])?$this->restrictions[$tag->getValue(1)]:null;
			if ($restrictions)
			{
				foreach ($restrictions as $restriction)
				{
					$tag->addRestriction($restriction);
				}
				
			}
			$tag->finishRestrictions();
		}
		}
		
	}
	
	protected function createRestrictionTag($line, $name)
	{
		$id = strtok(" \t");
		$val = strtok(" \t");
		$restr = new AIS_DocCommentTagJsonRestriction($name,$val);
		if (!isset($this->restrictions[$id]))
		{
			$this->restrictions[$id] = array();
		}
		array_push($this->restrictions[$id],$restr);
	}
	
    /**
     * @see AIS_DocComment::processTagLine()
     */
    protected function processTagLine($line, $name)
    {
    	$func = isset($this->tagFunctions[$name])?$this->tagFunctions[$name]:null;
		if ($func)
		{
			return $this->$func($line);
		}
		else{
			return parent::processTagLine($line,$name);
		}
        
    }
	/**
	 * 
	 * @return AIS_DocCommentTagParamWithRestriction 
	 * @param $string $id The id of the @param tag
	 */
	public function getParam($id)
	{
		return $this->params[$id];
	}
	
	

}

?>